﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Wicresoft.Common;
using JDEduTrain.Framework.Business;
using JDEduTrain.Framework.ViewEntity;
using JDEduTrain.Framework.Entity;
using Wicresoft.Framework.Organization;

public partial class Page_ClassMemberTrainDetailStat : BaseAuthenticationPage
{

    public string SearchDefaultText
    {
        get
        {
            return "搜索 学员名称";
        }
    }

    public string SearchClause
    {
        get
        {
            if (ViewState["SearchClause"] == null)
                ViewState["SearchClause"] = "1=1";
            return ViewState["SearchClause"].ToString();
        }
        set
        {
            ViewState["SearchClause"] = value;
        }
    }

    public Guid ClassID
    {
        get
        {
            if (Request["ClassID"] != null)
                return new Guid(Request["ClassID"]);
            return Guid.Empty;
        }
    }

    protected DataTable DTUserPageList
    {
        get
        {
            if (ViewState["DTUserPageList"] != null)
            {
                return (DataTable)ViewState["DTUserPageList"];
            }
            return new DataTable();
        }
        set
        {
            ViewState["DTUserPageList"] = value;
        }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        this.tbSearch.Attributes.Add("onfocus", string.Format("clearText(this, '{0}');", SearchDefaultText));
        this.tbSearch.Attributes.Add("onblur", string.Format("insertText(this, '{0}');", SearchDefaultText));
        this.tbSearch.Attributes.Add("onkeydown", "searchClick();");
        this.ShowLRLayoutButton = false;
        this.ShowUDLayoutButton = false;
        this.ShowSimpleLayoutButton = false;
        this.ShowAdvancedSearch = false;

        this.Title = "学员列表";
        if (!IsPostBack)
        {
            tbSearch.Text = SearchDefaultText;
            this.Order.OrderColumn = "ThirdLevelDeptDisplayName";
            this.Order.OrderDirection = "ASC";
            BindData();
        }

    }

    protected override void Pager_PageChanged(object sender, EventArgs e)
    {
        BindData();
        base.Pager_PageChanged(sender, e);
    }

    protected override void Order_OrderChanged(object sender, EventArgs e)
    {
        BindData();
        base.Order_OrderChanged(sender, e);
    }

    private void BindData()
    {
        int recordCount = 0;
        DTUserPageList = BLTrain.GetMemberByClassID(ClassID,"终审通过",this.Pager.PageIndex,Pager.PageSize,SearchClause,ClassMember.SQLCOL_CLASSID,ref recordCount);
        DTUserPageList.Columns.Add("YearScore");
        DTUserPageList.Columns.Add("TotalScore");
        DTUserPageList.Columns.Add("ThirdLevelDeptDisplayName");
        foreach (DataRow dr in DTUserPageList.Rows)
        {
            UserExtend userExtend = new UserExtend(new Guid(dr["ID"].ToString()));
            if (userExtend.Load())
            {
                //取三级实体部门
                Department dept = OrganizationHelper.GetDepartmentInfo(userExtend.MainDepartmentID);
                if (dept != null)
                {
                    string[] userDeptIDs = dept.IDPath.Split('/');
                    if (userDeptIDs.Length >= 4)
                    {
                        dr["ThirdLevelDeptDisplayName"] = OrganizationHelper.GetDepartmentInfo(new Guid(userDeptIDs[3])).DisplayName;
                    }
                }
            }
            dr["YearScore"] = BLTrain.GetYearScoreByMemberID(new Guid(dr["ID"].ToString()));
            dr["TotalScore"] = BLTrain.GetAllScoreByMemberID(new Guid(dr["ID"].ToString()));
            lClassName.Text = dr["ClassName"].ToString();
        }
        Pager.RecordCount = recordCount;
        rptUserInfo.DataSource = DTUserPageList;
        rptUserInfo.DataBind();

    }

    protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindData();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (tbSearch.Text != string.Empty && tbSearch.Text != SearchDefaultText)
            SearchClause = string.Format("{0} LIKE N'%{1}%'", ClassMember.SQLCOL_MEMBERNAME, tbSearch.Text);
        else
            SearchClause = "1=1";
        BindData();
    }
    protected void btnAdvancedSearch_Click(object sender, EventArgs e)
    {
        BindData();

    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        BindData();
    }

}
